package com.eva.job;

import com.eva.job.constants.JobConstants;
import com.eva.job.dto.TriggerJobDTO;
import lombok.extern.slf4j.Slf4j;
import org.quartz.JobExecutionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.QuartzJobBean;
import org.springframework.stereotype.Component;

/**
 * JOB处理器
 */
@Slf4j
@Component
public class JobHandler extends QuartzJobBean {

    @Autowired
    private SystemJobTrigger systemJobTriggerBiz;

    @Override
    protected void executeInternal(JobExecutionContext jobExecutionContext) {
        Integer jobId = jobExecutionContext.getMergedJobDataMap().getInt(JobConstants.DATA_MAP_JOB_ID);
        TriggerJobDTO dto = new TriggerJobDTO();
        dto.setId(jobId);
        dto.setTriggerType(JobConstants.TriggerType.SYSTEM.getCode());
        dto.setScheduledFireTime(jobExecutionContext.getScheduledFireTime());
        dto.setBusinessTime(jobExecutionContext.getScheduledFireTime());
        dto.setFireTime(jobExecutionContext.getFireTime());
        dto.setNextFireTime(jobExecutionContext.getTrigger().getNextFireTime());
        systemJobTriggerBiz.trigger(dto);
    }

}
